'use strict';

/**
 * 用户相关接口
 */
const userCtrl = require('../../controllers/user');
const router = require('koa-router')();
const multer = require('koa-multer');
const resConfig = require('../../../config/global_config').res;

// 内存缓存
const upload = multer({
    storage: multer.memoryStorage(),
    limits: {
        fieldSize: 5 * 1024 * 1024
    }
});

// 大文件上传
const storage = multer.diskStorage({
    //文件保存路径
    destination: function (req, file, cb) {
        cb(null, resConfig.uploader_dir)
    },
    //修改文件名称
    filename: function (req, file, cb) {
        var fileFormat = (file.originalname).split(".");
        cb(null, Date.now() + "." + fileFormat[fileFormat.length - 1]);
    }
});
const upload_large = multer({ storage: storage });

// 员工批量注册
router.post("/register_batch", upload.single('user_info_xlsx'), userCtrl.register_batch);
// 访客批量注册
router.post("/guest_register_batch", upload.single('user_info_xlsx'), userCtrl.guest_register_batch);
// 特征批量注册
router.post("/feature_register_batch", upload_large.single('image_zip'), userCtrl.feature_register_batch);
// 新增用户
router.post("/register", userCtrl.register);
// 更新用户信息
router.post("/update", userCtrl.update);
// 删除用户信息
router.post("/delete", userCtrl.delete);
// 将用户还原回陌生人
router.post("/recovery", userCtrl.recovery);
// 审核访客信息
router.post("/verify", userCtrl.verify);
// 查询员工信息
router.get("/query", userCtrl.query);
// 查询员工详情
router.get("/query_detail", userCtrl.query_detail);
// 查询员工特征（一览里面用到最多展示5张）
router.get("/query_avatar", userCtrl.query_avatar);
// 查询人脸特征（同时对APP开放）
router.get("/query_feature", userCtrl.query_feature);
// 特征注册
router.post("/register_feature", userCtrl.regFeature);
// 添加特征
router.post("/add_feature", userCtrl.addFeature);
// 特征删除
router.post("/delete_feature", userCtrl.delFeature);
// 特征合并
router.post("/merge_feature", userCtrl.merge_feature);
// 人脸识别
router.post("/recognize", userCtrl.recognize);


// 查询员工信息（仅对APP开放）
router.get("/query_users", userCtrl.query_users);
// // 查询员工头像（仅对APP开放）【没朋友的设计】 20171209已废弃
// router.get("/query_image", userCtrl.query_image);
// 新增访客（仅对APP开放）
router.post("/reg_guest", userCtrl.reg_guest);
// 删除访客（仅对APP开放）
router.post("/del_guest", userCtrl.del_guest);
// 更新显示头像（仅对APP开放）
router.post("/update_avatar", upload.single('avatar'), userCtrl.update_avatar);

router.post("/clean", userCtrl.clean);

// 学生
router.post("/add_student", userCtrl.add_student)
router.post("/update_student", userCtrl.update_student)
router.post("/delete_student", userCtrl.delete_student)
router.get("/get_student_by_id", userCtrl.get_student_by_id)
// 学生批量注册
router.post("/upload_student", upload.single('student_xlsx'), userCtrl.upload_student);

// 批量上传头像
router.post('/batch_upload_avatar', upload_large.single('image_zip'), userCtrl.batch_upload_avatar)

// 清空学生特征值
router.post("/empty_student_feature", userCtrl.empty_student_feature)

// 同步学生特征值
router.post("/sync_student_feature", userCtrl.sync_student_feature)


router.post('/batch_upload_student_avatar', upload_large.single('image_zip'), userCtrl.batch_upload_avatar)

router.post("/batch_upload_student", upload.single('student_xlsx'), userCtrl.upload_student);

router.post("/batch_update_library", userCtrl.batch_update_library)

module.exports = router;
